package com.example.kemusan.mapper;

import com.example.kemusan.pojo.ResultInfo;
import com.example.kemusan.pojo.StuInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface StuInfoMapper {

    /**
     * 查询所有考生
     * @return
     */
    @Select("select username, admission, car_type, id_card, image, status from stu_info where status > 0")
    public List<StuInfo> selectAll();

    /**
     * 添加考生
     * @param stuInfo
     * @return
     */
    @Insert("insert into stu_info values (#{username},#{admission},#{carType},#{idCard},#{image},default)")
    public Integer insertStu(StuInfo stuInfo);

    /**
     * 更新考生的status
     * @param idCard
     * @return
     */
    @Update("update stu_info set status = status - 1 where id_card = #{idCard} and status > 0")
    public Integer setStatus(String idCard);

    /**
     * 重置status为2
     * @param stuInfo
     * @return
     */
    @Update("update stu_info set status = 2 where id_card = #{idCard}")
    public Integer resetStatus(StuInfo stuInfo);

    @Update("update stu_info set status = 0 where id_card = #{idCard}")
    public Integer clearStatus(String idCard);

    /**
     * 根据idCard或admission查询用户
     * @param stuInfo
     * @return
     */
    public StuInfo selectStuByIdCardOrAdmission(StuInfo stuInfo);

    @Select("select id, id_card, finish_time, score, deduction_items from result_info where id_card = #{idCard} order by score desc")
    public List<ResultInfo> selectScoreByIdCard(StuInfo stuInfo);
}
